package com.pro.service.imple;

import com.pro.mapper.JsMicroLogMapper;
import com.pro.mapper.JsMicrocircleMapper;
import com.pro.pojo.JsMicroLog;
import com.pro.pojo.JsMicrocircle;
import com.pro.pojo.JsUser;
import com.pro.service.JsMicrocircleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * ClassName:JsMicrocircleServiceImple
 * Package:com.pro.service.imple
 * Description: 微圈表格
 *
 * @Date:2021/11/28 下午 8:30
 * @Author: WYH
 */
@Service
public class JsMicrocircleServiceImple implements JsMicrocircleService {


    @Autowired(required = false)
    private JsMicrocircleMapper jsMicrocircleMapper;

    @Autowired(required = false)
    private JsMicroLogMapper jsMicroLogMapper;

    @Override
    public List<JsMicrocircle> getTable(String acticleCategroyId,String artcleTitle , String trueName,String account) {
        List<JsMicrocircle> table = jsMicrocircleMapper.getTable(acticleCategroyId,artcleTitle,trueName,account);
        for (JsMicrocircle t : table) {
            int i = jsMicrocircleMapper.countShou((int)t.getMicrocircleId());
            t.setActicleCollection(i);
        }
        return table;
    }

    @Override
    public int count(String acticleCategroyId,String artcleTitle, String trueName, String account) {
        int count = jsMicrocircleMapper.count(acticleCategroyId,artcleTitle, trueName, account);
        return count;
    }

    //删除微圈
    @Override
    public Boolean deleteMicro(Integer microcircleId ,Integer createId) {
        Boolean flag=jsMicrocircleMapper.deleteMicro(microcircleId);

        /* 每次查看详情向日志表中添加数据 */
        JsMicroLog jsMicroLog = new JsMicroLog();
        jsMicroLog.setUserId(createId);
        jsMicroLog.setTableName("js_microcircle");
        jsMicroLog.setType("3");
        jsMicroLog.setCreateDate(new Date());
        jsMicroLog.setRemark("删除微圈");
        jsMicroLog.setLogType(3);
        Boolean addMicroLog = jsMicroLogMapper.addMicroLog(jsMicroLog);

        return flag;
    }

    //查看一门微圈的详细信息
    @Override
    public JsMicrocircle getMicMsg(Integer microcircleId,Integer createId) {
        JsMicrocircle msg=jsMicrocircleMapper.getMicMsg(microcircleId);

        /* 每次查看详情向日志表中添加数据 */
        JsMicroLog jsMicroLog = new JsMicroLog();
        jsMicroLog.setUserId(createId);
        jsMicroLog.setTableName("js_microcircle");
        jsMicroLog.setType("5");
        jsMicroLog.setCreateDate(new Date());
        jsMicroLog.setRemark("查看微圈详情");
        jsMicroLog.setLogType(3);
        Boolean addMicroLog = jsMicroLogMapper.addMicroLog(jsMicroLog);

        return msg;
    }

    @Override
    public JsUser getUser(String account, String password) {
        JsUser user=jsMicrocircleMapper.getUser(account,password);
        return user;
    }

    @Override
    public Boolean addMic(JsMicrocircle mic) {
        Boolean flag=jsMicrocircleMapper.addMic(mic);
        return flag;
    }

    @Override
    public int countShou(Integer microcircleId) {
        int i = jsMicrocircleMapper.countShou(microcircleId);
        return i;
    }
}
